package com.qf.day10_2;

/**
 * @author wgy
 * @version V1.0
 * @Project day10
 * @Package com.qf.day10_2
 * @Description: ${TODO}
 * @Date 2021/5/31 10:58
 */
public class Student {
    //属性
    //封装的步骤
    //(1) 属性添加private修饰符
    private String name;
    private int age;
    private String sex;
    private double score;
    //无参构造方法
    public Student(){

    }
    //带参构造方法
    public Student(String name,int age,String sex,double score){
//        this.name=name;
//        this.age=age;
//        this.sex=sex;
//        this.score=score;
        this.setName(name);
        this.setAge(age);
        this.setSex(sex);
        this.setScore(score);
    }
    //(2) 添加公开的get和set方法
    //(3) 添加逻辑判断过滤数据(可选)
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        if(age<0||age>100){
            this.age=18;
        }else {
            this.age = age;
        }
    }
    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        if(sex.equals("男")||sex.equals("女")) {
            this.sex = sex;
        }else{
            this.sex="男";
        }
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        if(score<=0||score>100){
            this.score=60;
        }else {
            this.score = score;
        }
    }

    //方法
    public void show(){
        System.out.println("姓名:"+this.name+" 年龄:"+this.age+" 性别:"+this.sex+"成绩:"+this.score);
    }

}
